package com.imot.controller;

import com.imot.response.Result;
import com.imot.service.EmaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;


/**
 * ClassName: FetchEMAController
 * Description:
 * date: 2023/11/7 16:08
 *
 * @author imot-jiah.wang
 */
@Slf4j
@RestController
@EnableScheduling
@RequestMapping("/api/getEmaData")
@RequiredArgsConstructor
@Api(tags = "实时数据控制器")
public class FetchEMAController {

    private final EmaService emaService;
    @ApiOperation("获取本机ip")
    @GetMapping("/getIp")
    public Result getIp(){
        Result result = emaService.getIp();
        return result;
    }

    @ApiOperation("获取机电作动器的状态态势")
    @GetMapping("/getEmaState")
    public Result getEmaState(){
        Result result = emaService.getEmaState();
        return result;
    }

    @ApiOperation("获取机电作动器的实时数据")
    @GetMapping("/getEmaRuntimeDate")
    public Result getEmaNow(){
        Result result = emaService.getEmaNow();
        return result;
    }

    @ApiOperation("获取状态监测波形图")
    @GetMapping("/getEmaWaveData")
    public Result getEmaWaveData(){
        Result result = emaService.getEmaWaveData();
        return result;
    }

    @ApiOperation("获取实验时长统计")
    @GetMapping("/getExpDuration")
    public Result expDuration(@RequestParam(value = "start",required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate start
            , @RequestParam(value = "end",required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        Result result = emaService.expDuration(start,end);
        return result;
    }

    @ApiOperation("获取模拟作动器的实况信息")
    @GetMapping("/getInjectFault")
    public Result injectFault(){
        Result result = emaService.injectFault();
        return result;
    }
}


